package com.turnengine.client.global.game.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.global.game.bean.IGameInstance;
import com.turnengine.client.global.game.command.NewGameInstance;

/**
 * The New Game Instance Servlet.
 */
public class NewGameInstanceServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, NewGameInstanceService {

	public IGameInstance newGameInstance(long loginId, String gameName, String versionName, String instanceName, int hostId) throws GwtErrorCodeException {
		NewGameInstance command = new NewGameInstance(loginId, gameName, versionName, instanceName, hostId);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<IGameInstance> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
